package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.config.passroad.BackEndPassRecord;
import com.yanqu.road.entity.config.passroad.PassRoadInfo;
import com.yanqu.road.entity.config.passroad.PassRoadPointInfo;
import com.yanqu.road.entity.config.passroad.UserPassRoadEvent;
import com.yanqu.road.entity.player.UserPassRoad;
import com.yanqu.road.pb.pass.RoadProto;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.util.List;


public class PassRoadPb {

	public static RoadProto.RoadTempMsg.Builder parsePassRoadTempMsg(UserPassRoad userPassRoad) {
		RoadProto.RoadTempMsg.Builder msg = RoadProto.RoadTempMsg.newBuilder();
		msg.setPassId(userPassRoad.getPassId());
		msg.setPassProgress(userPassRoad.getPassProgress());
		msg.setBuyBuffTimes(userPassRoad.getBuyBuffTimes());
		msg.setItemBuyBuffTimes(userPassRoad.getItemBuyBuffTimes());
		for(UserPassRoadEvent userEvent : userPassRoad.getUserPassRoadEvents()){
			RoadProto.EventDataTemp.Builder eventTmp = RoadProto.EventDataTemp.newBuilder();
			eventTmp.setPassId(userEvent.getPassId());
			eventTmp.setSectionId(userEvent.getSectionId());
			eventTmp.setEventId(userEvent.getEventId());
			eventTmp.setSessionId(userEvent.getSessionId());
			eventTmp.setSessionSectionId(userEvent.getSessionId());
			eventTmp.setCreateTime((int)(userEvent.getCreateTime()/1000));
			msg.addEvents(eventTmp);
		}
		return msg;
	}

	public static RoadProto.RoadConfigMsg.Builder parsePassRoadConfigMsg(List<PassRoadPointInfo> pointList, PassRoadInfo info,List<Integer> sliverCostParamList) {
		RoadProto.RoadConfigMsg.Builder msg = RoadProto.RoadConfigMsg.newBuilder();
		msg.setCostSilverMinParam(sliverCostParamList.get(0));
		msg.setCostSilverMaxParam(sliverCostParamList.get(1));
		for(PassRoadPointInfo point : pointList){
			RoadProto.RoadConfigTemp.Builder temp = RoadProto.RoadConfigTemp.newBuilder();
			Property reward = new Property();
			reward.addProperty(point.getReward());
			temp.setId(point.getId());
			temp.setSessionId(point.getSessionId());
			temp.setSessionSectionId(point.getSessionSectionId());
			temp.setSectionId(point.getSectionId());
			temp.setMoney(point.getBlood().toString());
			temp.setStrength(point.getAbility().toString());
			temp.setIsSessionEnd(point.isSessionEnd());
			temp.setIsBoss(point.isBoss());
			if(point.isSessionEnd()){
				temp.setEventId(point.getEventId());
			}
			if(point.isBoss()){
				temp.setBaseInspireConsume(Long.parseLong(info.getBaseInspireConsume()));
				reward.addProperty(PropertyHelper.parseStringToProperty(info.getRewards()));
			}
			temp.setRewards(PropertyHelper.parsePropertyToString(reward));
			msg.addConfigList(temp);
		}
		return msg;
	}

	public static RoadProto.PassRoadBackendDetailRespMsg.Builder parsePassRoadBackendDetailRespMsg(BackEndPassRecord record){
		RoadProto.PassRoadBackendDetailRespMsg.Builder builder = RoadProto.PassRoadBackendDetailRespMsg.newBuilder();
		builder.setBossReward(PropertyHelper.parsePropertyToString(record.getBossReward()));
		builder.setCost(PropertyHelper.parsePropertyToString(record.getCost()));
		builder.setNormalReward(PropertyHelper.parsePropertyToString(record.getNormalReward()));
		builder.setStopReason(record.getStopReason());
		builder.setEventNum(record.getEventNum());
		builder.setHadBackend(record.isHadBackend());
		builder.setStartPassId(record.getStartPassId());
		builder.setStartSessionId(record.getStartSessionId());
		builder.setEndPassId(record.getEndPassId());
		builder.setEndSessionId(record.getEndSessionId());
		return builder;
	}

	public static RoadProto.RoadTempMsg.Builder parsePassRoadTempMsg(UserPassRoad userPassRoad, int autoBuyBuffTimes, int autoItemBuyBuffTimes) {
		RoadProto.RoadTempMsg.Builder builder = parsePassRoadTempMsg(userPassRoad);
		builder.setAutoBuyBuffTimes(autoBuyBuffTimes);
		builder.setAutoItemBuyBuffTimes(autoItemBuyBuffTimes);
		return builder;
	}
}
